<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/jq.mselect.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.multiselect.js"></script>
<script type="text/javascript">
get_check = function(){
	var ids = '';
	$("#list").find("input[type='checkbox']").each(function(){
		if ($(this).is(":checked"))
		{
			if (ids)
			{
				ids += ',';
			}
			ids += $(this).val();
		}
	});
	return ids;
};
$(function(){
	$("#shop_ids, #site").multiselect({height: 260, minWidth: 160});
	$(".datepicker").datepicker({dateFormat: 'yy-mm-dd', changeMonth: true});
	$("#check_all").click(function(){if ($(this).is(":checked")){$("#list input[type='checkbox']").attr("checked", true);}else{$("#list input[type='checkbox']").attr("checked", false);}});
	$("#multi_inventory_btn").click(function(){
		var ids = get_check();
		if ( ! ids)
		{
			alert('请选择SKU');
			return false;
		}
		var url = '<?=url('Online::EbayListing/ReviseInventory')?>&ids=' + ids;
		$("#multi_inventory_link").attr("href", url).click();
	});
	$("#multi_inventory_link").colorbox({iframe: true, slideshow:true, slideshowAuto: false, width: '700px', height: '60%', maxHeight: '90%'});
	$("#multi_keep_quantity_btn").click(function(){
		var ids = get_check();
		if ( ! ids)
		{
			alert('请选择SKU');
			return false;
		}
		var url = '<?=url('Online::EbayListing/KeepQuantity')?>&ids=' + ids;
		$("#multi_keep_quantity_link").attr("href", url).click();
	});
	$("#multi_keep_quantity_link").colorbox({iframe: true, slideshow:true, slideshowAuto: false, width: '800px', height: '60%', maxHeight: '90%'});
});
</script>

<fieldset><legend>查询条件</legend>
<form method="get" action="">
<?include(Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
<table class="form_table">
<tr>
	<th>店铺</th>
	<td>
		<select name="shop_ids[]" multiple="multiple" id="shop_ids">
			<?foreach ($shop as $s):?>
			<option value="<?=$s['id']?>" <?if (isset($_GET['shop_ids']) && in_array($s['id'], $_GET['shop_ids'])):?>selected="selected"<?endif;?>><?=$s['name']?></option>
			<?endforeach;?>
		</select>
	</td>
	<th>站点</th>
	<td>
		<select name="site[]" multiple="multiple" id="site">
			<?foreach (Q::ini('custom_flag/online_ebay_listing_site') as $oels):?>
			<option value="<?=$oels['value']?>" <?if (isset($_GET['site']) && in_array($oels['value'], $_GET['site'])):?>selected="selected"<?endif;?>><?=$oels['name']?> - <?=$oels['value']?></option>
			<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>上架时间</th>
	<td>
		<input type="text" name="begin_start_time" value="<?=isset($_GET['begin_start_time']) ? $_GET['begin_start_time'] : ''?>" class="datepicker" /> to
		<input type="text" name="end_start_time" value="<?=isset($_GET['end_start_time']) ? $_GET['end_start_time'] : ''?>" class="datepicker" />
	</td>
	<th>下架时间</th>
	<td>
		<input type="text" name="begin_end_time" value="<?=isset($_GET['begin_end_time']) ? $_GET['begin_end_time'] : ''?>" class="datepicker" /> to
		<input type="text" name="end_end_time" value="<?=isset($_GET['end_end_time']) ? $_GET['end_end_time'] : ''?>" class="datepicker" />
	</td>
</tr>
<tr>
	<th>SKU</th>
	<td colspan="3"><input type="text" name="sku" value="<?=isset($_GET['sku']) ? $_GET['sku'] : ''?>" size="70" /></td>
</tr>
<tr>
	<th>Item ID</th>
	<td><input type="text" name="item_id" value="<?=isset($_GET['item_id']) ? $_GET['item_id'] : ''?>" /></td>
</tr>
<tr>
	<th>在线状态</th>
	<td colspan="3">
		<?foreach (Q::ini('custom_flag/online_ebay_listing_sell_status') as $oelss):?>
		<label><input type="checkbox" name="sell_status[]" value="<?=$oelss['value']?>" <?if (isset($_GET['sell_status']) && in_array($oelss['value'], $_GET['sell_status'])):?>checked="checked"<?endif;?> /><?=$oelss['name']?></label>
		<?endforeach;?>
	</td>
</tr>
<tr>
	<th>类型</th>
	<td colspan="3">
		<?foreach (Q::ini('custom_flag/online_ebay_listing_type') as $oelt):?>
		<label><input type="checkbox" name="listing_type[]" value="<?=$oelt['value']?>" <?if (isset($_GET['listing_type']) && in_array($oelt['value'], $_GET['listing_type'])):?>checked="checked"<?endif;?> /><?=$oelt['name']?></label>
		<?endforeach;?>
	</td>
</tr>
<tr>
	<th>多数量</th>
	<td colspan="3">
		<?foreach (Q::ini('custom_flag/online_ebay_listing_variation') as $oelv):?>
		<label><input type="checkbox" name="variation[]" value="<?=$oelv['value']?>" <?if (isset($_GET['variation']) && in_array($oelv['value'], $_GET['variation'])):?>checked="checked"<?endif;?> /><?=$oelv['name']?></label>
		<?endforeach;?>
	</td>
</tr>
<tr>
	<th>维持数量</th>
	<td colspan="3">
		<?foreach (Q::ini('custom_flag/online_ebay_listing_item_keep_quantity_flag') as $f):?>
		<label><input type="checkbox" name="keep_quantity_flag[]" value="<?=$f['value']?>" <?if (isset($_GET['keep_quantity_flag']) && in_array($f['value'], $_GET['keep_quantity_flag'])):?>checked="checked"<?endif;?> /><?=$f['name']?></label>
		<?endforeach;?>
	</td>
</tr>
<tr>
	<td></td>
	<td><input type="submit" value="查询" class="button" /></td>
</tr>
</table>
</form></fieldset>

<table class="list_table" style="table-layout: fixed;" width="98%" id="list">
<tr>
	<th width="20"></th>
	<th width="70">
		<a href= "<?=$url?>&sort_by=<?='sku'?>&sort_order=<?=(isset($_GET['sort_by']) && ($_GET['sort_by'] == 'sku') && ($_GET['sort_order'] == 'desc')) ? 'asc' : 'desc'?>">SKU</a>
		<?=(isset($_GET['sort_by']) && $_GET['sort_by'] == 'sku') ? ($_GET['sort_order'] == 'asc' ? '↑' : '↓') : ''?>
	</th>
	<th width="130">
		<a href="<?=$url?>&sort_by=<?='online_ebay_listing.item_id'?>&sort_order=<?=(isset($_GET['sort_by']) && ($_GET['sort_by'] == 'online_ebay_listing.item_id') && ($_GET['sort_order'] == 'desc')) ? 'asc' : 'desc'?>" >Item ID</a>
		<?=(isset($_GET['sort_by']) && $_GET['sort_by'] == 'online_ebay_listing.item_id') ? ($_GET['sort_order'] == 'asc' ? '↑' : '↓') : ''?>
	</th>
	<th width="130">
		<a href="<?=$url?>&sort_by=<?='shop.name'?>&sort_order=<?=(isset($_GET['sort_by']) && ($_GET['sort_by'] == 'shop.name') && ($_GET['sort_order'] == 'desc')) ? 'asc' : 'desc'?>" >店铺</a>
		<?=(isset($_GET['sort_by']) && $_GET['sort_by'] == 'shop.name') ? ($_GET['sort_order'] == 'asc' ? '↑' : '↓') : ''?>
	</th>
	<th width="80">
		<a href="<?=$url?>&sort_by=<?='online_ebay_listing.site'?>&sort_order=<?=(isset($_GET['sort_by']) && ($_GET['sort_by'] == 'online_ebay_listing.site') && ($_GET['sort_order'] == 'desc')) ? 'asc' : 'desc'?>" >站点</a>
		<?=(isset($_GET['sort_by']) && $_GET['sort_by'] == 'online_ebay_listing.site') ? ($_GET['sort_order'] == 'asc' ? '↑' : '↓') : ''?>
	</th>
	<th width="110">
		<a href="<?=$url?>&sort_by=<?='online_ebay_listing.listing_type'?>&sort_order=<?=(isset($_GET['sort_by']) && ($_GET['sort_by'] == 'online_ebay_listing.listing_type') && ($_GET['sort_order'] == 'desc')) ? 'asc' : 'desc'?>" >类型</a>
		<?=(isset($_GET['sort_by']) && $_GET['sort_by'] == 'online_ebay_listing.listing_type') ? ($_GET['sort_order'] == 'asc' ? '↑' : '↓') : ''?>
	</th>
	<th width="100">
		<a href="<?=$url?>&sort_by=<?='online_ebay_listing.variation'?>&sort_order=<?=(isset($_GET['sort_by']) && ($_GET['sort_by'] == 'online_ebay_listing.variation') && ($_GET['sort_order'] == 'desc')) ? 'asc' : 'desc'?>" >多数量</a>
		<?=(isset($_GET['sort_by']) && $_GET['sort_by'] == 'online_ebay_listing.variation') ? ($_GET['sort_order'] == 'asc' ? '↑' : '↓') : ''?>
	</th>
	<th width="60">
		<a href="<?=$url?>&sort_by=<?='online_ebay_listing.listing_duration'?>&sort_order=<?=(isset($_GET['sort_by']) && ($_GET['sort_by'] == 'online_ebay_listing.listing_duration') && ($_GET['sort_order'] == 'desc')) ? 'asc' : 'desc'?>" >周期</a>
		<?=(isset($_GET['sort_by']) && $_GET['sort_by'] == 'online_ebay_listing.listing_duration') ? ($_GET['sort_order'] == 'asc' ? '↑' : '↓') : ''?>
	</th>
	<th width="80">
		<a href="<?=$url?>&sort_by=<?='online_ebay_listing.sell_status'?>&sort_order=<?=(isset($_GET['sort_by']) && ($_GET['sort_by'] == 'online_ebay_listing.sell_status') && ($_GET['sort_order'] == 'desc')) ? 'asc' : 'desc'?>" >在线状态</a>
		<?=(isset($_GET['sort_by']) && $_GET['sort_by'] == 'online_ebay_listing.sell_status') ? ($_GET['sort_order'] == 'asc' ? '↑' : '↓') : ''?>
	</th>
	<th width="70">
		<a href="<?=$url?>&sort_by=<?='start_price'?>&sort_order=<?=(isset($_GET['sort_by']) && ($_GET['sort_by'] == 'start_price') && ($_GET['sort_order'] == 'desc')) ? 'asc' : 'desc'?>" >价格</a>
		<?=(isset($_GET['sort_by']) && $_GET['sort_by'] == 'start_price') ? ($_GET['sort_order'] == 'asc' ? '↑' : '↓') : ''?>
	</th>
	<th width="45">
		<a href="<?=$url?>&sort_by=<?='quantity'?>&sort_order=<?=(isset($_GET['sort_by']) && ($_GET['sort_by'] == 'quantity') && ($_GET['sort_order'] == 'desc')) ? 'asc' : 'desc'?>" >在线数</a>
		<?=(isset($_GET['sort_by']) && $_GET['sort_by'] == 'quantity') ? ($_GET['sort_order'] == 'asc' ? '↑' : '↓') : ''?>
	</th>
	<th width="45">
		<a href="<?=$url?>&sort_by=<?='sold_quantity'?>&sort_order=<?=(isset($_GET['sort_by']) && ($_GET['sort_by'] == 'sold_quantity') && ($_GET['sort_order'] == 'desc')) ? 'asc' : 'desc'?>" >已售数</a>
		<?=(isset($_GET['sort_by']) && $_GET['sort_by'] == 'sold_quantity') ? ($_GET['sort_order'] == 'asc' ? '↑' : '↓') : ''?>
	</th>
	<th width="80">Location</th>
	<th width="50">维持数量</th>
	<th width="50">可用库存</th>
	<th width="50">销售状态</th>
	<th width="50">采购状态</th>
</tr>
<?foreach ($item as $i):?>
<tr>
	<td><input type="checkbox" value="<?=$i['id']?>" /></td>
	<td><?=$i['sku']?></td>
	<td><a href="<?=$i['view_url']?>" target="_blank"><?=$i['item_id']?></a></td>
	<td><?=$i['shop_name']?></td>
	<td><?=$i['site']?></td>
	<td><?=Helper_BSS_Normal::getIniOne('online_ebay_listing_type', 'value', $i['listing_type'], 'name')?></td>
	<td><?=Helper_BSS_Normal::getIniOne('online_ebay_listing_variation', 'value', $i['variation'], 'name')?></td>
	<td><?=$i['listing_duration']?></td>
	<td><?=Helper_BSS_Normal::getIniOne('online_ebay_listing_sell_status', 'value', $i['sell_status'], 'name')?></td>
	<td><?=$i['currency_code']?> <?=$i['start_price']?></td>
	<td><?=$i['quantity']?></td>
	<td><?=$i['sold_quantity']?></td>
	<td><?=$i['location']?></td>
	<td><?if ($i['keep_quantity_flag'] == Q::ini('custom_flag/online_ebay_listing_item_keep_quantity_flag/keep/value')):?><?=$i['keep_quantity']?><?endif;?></td>
	<td><?if (isset($i['available_quantity'])): ?><?=$i['available_quantity'] ?><?endif;?></td>
	<td><font color="#<?=Helper_BSS_Normal::getIniOne('product_sales_status', 'value', $i['sales_status'], 'color')?>"><?if (isset($i['sales_status'])): ?><?=Helper_BSS_Normal::getIniOne('product_sales_status', 'value', $i['sales_status'], 'name') ?><?endif;?></font></td>
	<td><font color="#<?=Helper_BSS_Normal::getIniOne('product_purchase_status', 'value', $i['purchase_status'], 'color')?>"><?if (isset($i['purchase_status'])): ?><?=Helper_BSS_Normal::getIniOne('product_purchase_status', 'value', $i['purchase_status'], 'name') ?><?endif;?></font></td>
</tr>
<?endforeach;?>
</table>
<?=$page?>
<table class="list_table">
<tr>
	<td><label><input type="checkbox" id="check_all" />全选</label></td>
	<td>
		<input type="button" value="批量改数量&价格" class="button" style="width: 120px" id="multi_inventory_btn" /><a href="" id="multi_inventory_link"></a>
		<input type="button" value="批量设置维持数量" class="button" style="width: 120px;" id="multi_keep_quantity_btn" /><a href="" id="multi_keep_quantity_link"></a>
	</td>
</tr>
</table>
<?php $this->_endblock();?>